package com.pv.user.controller;

import cn.hutool.core.util.PhoneUtil;
import com.pv.common.utils.R;
import com.pv.user.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: Zk
 * @Date: 2021/8/26 9:37
 */
@Slf4j
@RestController
@RequestMapping("user/sms")
public class SmsController {
    @Autowired
    private SmsService smsService;
    /**
     * 发送短信验证码
     *
     * @param phone
     * @return
     */
    @PostMapping(value = "/sendSmsCode", params = { "phone" })
    public R sendSmsCode(String phone) {
        if (!PhoneUtil.isMobile(phone)) {
            return R.error("手机号格式不正确");
        }
        smsService.sendSmsCode(phone);
        return R.ok();
    }
}
